package com.sky.shop.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.sky.dto.ShopDTO;
import com.sky.entity.Shop;
import com.sky.shop.mapper.ShopMapper;
import com.sky.shop.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 店铺管理 serviceImpl
 */
@Slf4j
@Service
public class ShopServiceImpl implements ShopService {

    @Resource
    private ShopMapper shopMapper;


    /**
     * 店铺
     *     修改店铺营业状态
     * @param shopDTO
     */
    @Override
    public void updateShopStatus(ShopDTO shopDTO) {
        // 1.对象拷贝 封装数据
        Shop shop = JSON.parseObject(JSON.toJSONString(shopDTO, SerializerFeature.WriteMapNullValue), Shop.class);
        // 2.调用方法
        Integer count = shopMapper.updateShopStatus(shop);
        log.info("店铺管理 - 修改店铺营业状态,影像数据行数: {}", count);
    }



    /**
     * 店铺
     *     查询店铺营业状态
     * @param shop
     */
    @Override
    public Integer selectShopStatus(Shop shop) {
        return shopMapper.selectShopStatus(shop);
    }



    /**
     * 定时任务
     * 店铺管理
     *        根据店铺名称和营业状态 查询
     * @param shopName
     * @param status
     */
    @Override
    public Shop getShopByNameAndStatus(String shopName, Integer status) {
        return shopMapper.selectShopByNameAndStatus(shopName, status);
    }

}
